package com.base.commonlib.utils;

import android.app.Activity;

import com.base.commonlib.bean.TaskInfo;

import java.io.File;
import java.io.IOException;

/**
 * Created by weikailiang on 2019/11/20.
 */

public class PdfUtils {
    public DownLoadUtils downLoadUtils;
    public void getPdf(String url, String name, Activity mActivity){
        String[] names = url.split("\\.");
        String fileName = name+"."+names[names.length-1];

        File file = new File(SystemUtil.getAppDir());
        if (!file.exists()){
            file.mkdirs();
        }
        File file1 = new File(SystemUtil.getAppDir()+fileName);
        if (file1.exists()){
            file1.delete();
            try {
                file1.createNewFile();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }else {
            file1.mkdirs();
            try {
                file.createNewFile();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        TaskInfo info = new TaskInfo();
        info.setName(fileName);
        info.setPath(SystemUtil.getAppDir());
        info.setUrl(url);
        downLoadUtils = new DownLoadUtils(mActivity,info,true);
        downLoadUtils.showDownDialog();
    }
    public void onDestory(){
        if (downLoadUtils!=null) {
            downLoadUtils.onDestory();
        }
    }
}
